home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / lib / int.mli < prev    next >
Encoding:
Text File  |  1993-09-24  |  3.7 KB  |  92 lines  |  [TEXT/MPS ]

  1. (* Operations on integers *)
  2.  
  3. (* Integers are 31 bits wide. All operations are taken modulo $2^{31}$.
  4.    They do not fail on overflow. *)
  5.  
  6. exception Division_by_zero;;
  7.  
  8. value minus : int -> int = 1 "~int"
  9.   and minus_int : int -> int = 1 "~int"
  10.         (* Unary negation. You can write [-e] instead of [minus e]. *)
  11.   and succ : int -> int = 1 "succ"
  12.         (* [succ x] is [x+1]. *)
  13.   and pred : int -> int = 1 "pred"
  14.         (* [pred x] is [x-1]. *)
  15.   and prefix + : int -> int -> int = 2 "+int"
  16.   and add_int : int -> int -> int = 2 "+int"
  17.         (* Addition. *)
  18.   and prefix - : int -> int -> int = 2 "-int"
  19.   and sub_int : int -> int -> int = 2 "-int"
  20.         (* Subtraction. *)
  21.   and prefix * : int -> int -> int = 2 "*int"
  22.   and mult_int : int -> int -> int = 2 "*int"
  23.         (* Multiplication. *)
  24.   and prefix / : int -> int -> int = 2 "div"
  25.   and div_int : int -> int -> int = 2 "div"
  26.   and prefix quo : int -> int -> int = 2 "div"
  27.         (* Integer division. Raise [Division_by_zero] if the second argument
  28.            is 0. Give unpredictable results if either argument is negative. *)
  29.   and prefix mod : int -> int -> int = 2 "mod"
  30.         (* Remainder. Raise [Division_by_zero] if the second argument is 0.
  31.            Give unpredictable results if either argument is negative. *)
  32.   and eq_int : int -> int -> bool = 2 "=int"
  33.         (* Integer equality. Equivalent to generic equality, just faster. *)
  34.   and neq_int : int -> int -> bool = 2 "<>int"
  35.         (* Negation of [eq_int]. *)
  36.   and prefix < : int -> int -> bool = 2 "<int"
  37.   and lt_int : int -> int -> bool = 2 "<int"
  38.   and prefix > : int -> int -> bool = 2 ">int"
  39.   and gt_int : int -> int -> bool = 2 ">int"
  40.   and prefix <= : int -> int -> bool = 2 "<=int"
  41.   and le_int : int -> int -> bool = 2 "<=int"
  42.   and prefix >= : int -> int -> bool = 2 ">=int"
  43.   and ge_int : int -> int -> bool = 2 ">=int"
  44.         (* Usual comparisons between integers. *)
  45. ;;
  46.  
  47. value min : int -> int -> int
  48.         (* Return the smaller of the arguments. *)
  49.   and max : int -> int -> int
  50.         (* Return the greater of the arguments. *)
  51.   and abs : int -> int
  52.         (* Return the absolute value of the argument. *)
  53. ;;
  54.  
  55. (*** Bitwise operations *)
  56.  
  57. value prefix land : int -> int -> int = 2 "and"
  58.         (* Bitwise logical and. *)
  59.   and prefix lor : int -> int -> int = 2 "or"
  60.         (* Bitwise logical or. *)
  61.   and prefix lxor : int -> int -> int = 2 "xor"
  62.         (* Bitwise logical exclusive or. *)
  63.   and lnot : int -> int
  64.         (* Bitwise complement *)
  65.   and prefix lsl : int -> int -> int = 2 "shift_left"
  66.   and lshift_left : int -> int -> int = 2 "shift_left"
  67.         (* [n lsl m], or equivalently [lshift_left n m], shifts [n] to the
  68.            left by [m] bits. *)
  69.   and prefix lsr : int -> int -> int = 2 "shift_right_unsigned"
  70.         (* [n lsr m] shifts [n] to the right by [m] bits.
  71.             This is a logical shift: zeroes are inserted regardless of sign.*)
  72.   and prefix asr : int -> int -> int = 2 "shift_right_signed"
  73.   and lshift_right : int -> int -> int = 2 "shift_right_signed"
  74.         (* [n asr m], or equivalently [lshift_right n m], shifts [n] to the
  75.            right by [m] bits.
  76.            This is an arithmetic shift: the sign bit is replicated. *)
  77. ;;
  78.  
  79. (*** Conversion functions *)
  80.  
  81. value string_of_int : int -> string
  82.         (* Convert the given integer to its decimal representation. *)
  83.   and int_of_string : string -> int = 1 "int_of_string"
  84.         (* Convert the given string to an integer, in decimal (by default)
  85.            or in hexadecimal, octal or binary if the string begins with
  86.            [0x], [0o] or [0b].
  87.            Raise [Failure "int_of_string"] if the given string is not
  88.            a valid representation of an integer. *)
  89. (*--*)
  90.   and format_int : string -> int -> string = 2 "format_int"
  91. ;;
  92.